package com.yunhe.device.repository.authority.impl;


import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.yunhe.common.model.authority.RealStation;
import com.yunhe.common.model.office.Office;
import org.neo4j.ogm.model.Result;
import org.neo4j.ogm.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.*;


/**
 * @author zhengbo
 * @date 2021/5/11 15:37
 */
@Repository
public class AuthorityDao  {

    @Autowired
    private Session session;


    public Long findRealStationByStationIdAndTitle(Long stationId, String value) {
        StringBuffer cql=new StringBuffer();
        //拼接基本语句
        cql.append("match(rt:RealStation)-[r:BELONG_TO_STATION{stationId:"+stationId+"}]->(station:Station) where 1=1 and (rt.enterpriseFullName='"+value);
        cql.append("' or rt.abbreviationName='"+value+"') return ID(rt)");
        Long id = session.queryForObject(Long.class, cql.toString(), Maps.newHashMap());
        return id;
    }

    public Long findOfficeByStationIdAndTitle(Long ownedPark, String officeTitle, Long stationId) {
        StringBuffer cql=new StringBuffer();
        //拼接基本语句
        cql.append("match(o:Office{officeTitle:'"+officeTitle+"'})<-[r:HAS_OFFICES]-(rt:RealStation)-[bts:BELONG_TO_STATION]->(s:Station) where 1=1 ");
        cql.append(" and ID(s)="+stationId+" and ID(rt)="+ownedPark+"  return ID(o) ");
        Long id = session.queryForObject(Long.class,cql.toString(),  Maps.newHashMap());
        return id;
    }
}
